﻿package net.wangit.adm.variables;

import net.wangit.LabelUtil;
import net.wangit.context.ActionContext;
import net.wangit.jdbc.DB;
import net.wangit.support.action.TransactionAction;
import net.wangit.util.Checker;

public class DeleteVariableAction extends TransactionAction {

	private static final String CONFIRM = "select * from AVARIABLES where parentid=?";
	private static final String DELETE = "delete from AVARIABLES where vid=?";

	public DeleteVariableAction() {
	}

	public void doAction(DB db, ActionContext ac) throws Exception {
		String id = ac.getRequestParameter("vid");
		net.wangit.MapList list = db.query(
				"select * from AVARIABLES where parentid=?", id, 2);
		if (!Checker.isEmpty(list)) {
			ac.getActionResult().setSuccessful(false);
			ac.getActionResult().addError(
					LabelUtil.get(ac, "adm", "variable.has_subnodes", id));
		} else {
			db.execute("delete from AVARIABLES where vid=?", id, 2);
		}
	}
}
